package com.tang.thepath;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class InvoiceActivity extends BaseActivity implements View.OnClickListener,View.OnLongClickListener {

    private Button btnCopy;
    private TextView tvCompanyName;
    private TextView tvAddress;
    private TextView tvMobile;
    private TextView tvTaxPayerNo;
    private TextView tvBank;
    private TextView tvBankNo;
    private TextView tvBankNo1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invoice);

        tvCompanyName = (TextView) findViewById(R.id.tv_company_name);
        tvAddress = (TextView) findViewById(R.id.tv_address);
        tvMobile = (TextView) findViewById(R.id.tv_mobile);
        tvTaxPayerNo = (TextView) findViewById(R.id.tv_taxpayer_no);
        tvBank = (TextView) findViewById(R.id.tv_bank);
        tvBankNo = (TextView) findViewById(R.id.tv_bank_no);
        tvBankNo1 = (TextView) findViewById(R.id.tv_bank_no1);

        tvCompanyName.setOnLongClickListener(this);
        tvAddress.setOnLongClickListener(this);
        tvMobile.setOnLongClickListener(this);
        tvTaxPayerNo.setOnLongClickListener(this);
        tvBank.setOnLongClickListener(this);
        tvBankNo.setOnLongClickListener(this);
        tvBankNo1.setOnLongClickListener(this);

        btnCopy = (Button) findViewById(R.id.btn_copy);
        btnCopy.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.btn_copy){
            StringBuffer sb = new StringBuffer();
            sb.append("公司名称:"+tvCompanyName.getText().toString()+"\r\n");
            sb.append("公司地址:"+tvAddress.getText().toString()+"\r\n");
            sb.append("联系电话:"+tvMobile.getText().toString()+"\r\n");
            sb.append("纳税人识别号:"+tvTaxPayerNo.getText().toString()+"\r\n");
            sb.append("开户行:"+tvBank.getText().toString()+"\r\n");
            sb.append("帐号:"+tvBankNo.getText().toString()+"\r\n");
            sb.append("跨行行号:"+tvBankNo1.getText().toString());

            ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("simple text copy", sb.toString());
            cm.setPrimaryClip(clipData);
            toast("复制成功");
        }
    }

    @Override
    public boolean onLongClick(View v) {
        long id = v.getId();
        if(id == R.id.tv_company_name
                || id == R.id.tv_address
                || id == R.id.tv_mobile
                || id == R.id.tv_taxpayer_no
                || id == R.id.tv_bank
                || id == R.id.tv_bank_no
                || id == R.id.tv_bank_no1){
            TextView textView = (TextView) v;
            ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("simple text copy", textView.getText().toString());
            cm.setPrimaryClip(clipData);
            toast("复制成功");
        }
        return false;
    }
}
